package com.hexacta.hrs.sandbox.meetings.data;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.hexacta.hrs.sandbox.meetings.model.Activity;
import com.hexacta.hrs.sandbox.meetings.model.Meeting;
import com.hexacta.hrs.sandbox.meetings.model.Theme;

/**
 * Persiste la clase Meeting.
 * @author ncortinez
 *
 */
public class MeetingDAO extends HibernateDaoSupport {
    public void saveOrUpdate(Meeting reunion) {
        this.getHibernateTemplate().saveOrUpdate(reunion);
    }

    public void delete(Meeting reunion) {
        this.getHibernateTemplate().delete(reunion);
    }
    
    public Meeting findById(Long id) {
        Meeting meeting = (Meeting) this.getHibernateTemplate().get(Meeting.class, id);
        this.inicializar(meeting);
        return meeting;
    }
    
    private void inicializar(Meeting meeting){
    	// FIXME no queremos recorrer todas las colecciones para cargar los datos. y si levantamos en eager?
		for(Meeting m : meeting.getMentor().getMeetings()){
	    	for (Theme t : m.getThemes()) {
				for(Activity a : t.getActivities()){
					a.getId();
				}
			}
		}
	}
}
